package ds_recommended.self_chuli

import org.apache.spark.sql.SparkSession

import java.util.Properties

object top5_product_image_url_to_update {
  def main(args: Array[String]): Unit = {
    val spark=SparkSession.builder()
      .master("local[*]")
      .appName("更改热门前五的图片的图片的连接")
      .getOrCreate()




    val connect=new Properties()
    connect.setProperty("user","root")
    connect.setProperty("password","123456")
    connect.setProperty("driver","com.mysql.jdbc.Driver")


    spark.read.jdbc("jdbc:mysql://192.168.67.193:3307/ods?useSSL=false","shop_info",connect)
      .createOrReplaceTempView("shop_info")

    spark.read.jdbc("jdbc:mysql://192.168.67.193:3307/dws?useSSL=false","top5_product",connect)
      .createOrReplaceTempView("product")


    val result=spark.sql(
      """
        |select
        |p.product_id,p.sell_number,p.zhanbi,p.rating,p.price,p.title,
        |s.image_url,p.class_name,s.info_url
        |from product as p
        |join shop_info as s
        |on s.product_id=p.product_id
        |""".stripMargin)

    result.write.mode("overwrite")
      .jdbc("jdbc:mysql://192.168.67.193:3307/dws?useSSL=false","top5_product",connect)
    spark.close()
  }

}
